import java.util.Arrays;

public class Text2 {
    //611.有效三角形的个数
    public int triangleNumber(int[] nums) {
        Arrays.sort(nums);

        int ret = 0,n = nums.length - 1;
        for(int i = n;i >= 2;i--){
            int left = 0,right = i - 1;
            while(left<right){
                if (nums[left] + nums[right] > nums[i]){
                    ret += (right - left);
                    right--;
                } else {
                    left++;
                }
            }
        }

        return ret;
    }
}
